package com.xingdata.jjxc.activity;

import jar.MessageManager;
import jar.model.RequestEntity;
import jar.tools.InstructionSet;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.xingdata.jjxc.R;
import com.xingdata.jjxc.base.Base1Activity;
import com.xingdata.jjxc.utils.SystemInfo;
import com.xingdata.jjxc.wifi.WifiAdapter;

/**
 * 
 * @ClassName: HotspotSettingActivity
 * @Description: TODO(WIFI设置)
 * @author JiangMin
 * @date 2016-4-14 下午1:44:43
 * 
 */
public class HotspotSettingActivity extends Base1Activity implements
		OnClickListener {
	private ImageView hideImageView;
	private EditText passwordEditText, usernameEditText;
	private boolean isHide = false;

	@Override
	protected int getContentViewId() {
		return R.layout.hotspot_setting;
	}

	@Override
	protected String getTitleText() {
			return "设置手机热点";
	}

	@Override
	protected void initViews() {
		hideImageView = ((ImageView) findViewById(R.id.hide_password));
		hideImageView.setOnClickListener(this);
		passwordEditText = (EditText) findViewById(R.id.password);
		usernameEditText = (EditText) findViewById(R.id.username);
		hideImageView.setBackgroundResource(R.drawable.hide_password_normal);
		findViewById(R.id.modifly_btn).setOnClickListener(this);

	}

	@Override
	public void onClick(View view) {

		switch (view.getId()) {
		case R.id.hide_password:
			if (isHide) {
				passwordEditText
						.setTransformationMethod(PasswordTransformationMethod
								.getInstance());
				hideImageView
						.setBackgroundResource(R.drawable.hide_password_presssd);

			} else {
				passwordEditText
						.setTransformationMethod(HideReturnsTransformationMethod
								.getInstance());
				hideImageView
						.setBackgroundResource(R.drawable.hide_password_normal);
			}
			isHide = !isHide;
			passwordEditText.postInvalidate();
			passwordEditText.setSelection(passwordEditText.getText().toString()
					.length());
			break;

		case R.id.modifly_btn:
			String strUserName = usernameEditText.getText().toString().trim();
			String strPassWord = passwordEditText.getText().toString().trim();
			if (strUserName.length() == 0 || strPassWord.length() == 0) {
				showToast("热点名称不能为空");
				return;
			} else if (strPassWord.length() == 0) {
				showToast("密码不能为空");
				return;
			}
			WifiAdapter.InitInstance(HotspotSettingActivity.this).strSSID = strUserName;
			WifiAdapter.InitInstance(HotspotSettingActivity.this).strPass = strPassWord;
			WifiAdapter.InitInstance(HotspotSettingActivity.this).setWIFIMode(WifiAdapter.Mode_AP);;
//			JSONObject jsonObject = new JSONObject();
//			jsonObject.put("wifi_name", strUserName);
//			jsonObject.put("wifi_pwd", strPassWord);
//			jsonObject.put("flag", "0");
//			MessageManager
//					.send(Integer.parseInt(SystemInfo.getSendPORT()),
//							new RequestEntity(
//									jsonObject.toJSONString(),
//									InstructionSet.INSTRUCTION_AUTH_HOTSPOT_TO_HUD
//											+ ""));
//			showToast("WIFI密码设置成功！");
			finish();
			break;

		default:
			break;
		}

	}

}
